﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddGbmpDynamicPannelUtils.h"
#include "IGalleryDefinition.h"
#include "GcmpActionBase.h"
#include "IRibbonGroup.h"
#include "GbmpUiPlatformCommandIds.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

namespace
{
    // 基于新UI框架实现的Gallery
    OwnerPtr<IGalleryDefinition> CreateDrawGalleryDefinition(IAction* pAction, const std::vector<std::wstring>& cmdStrings,
        const std::vector<std::wstring>& names, const std::vector<std::wstring>& icons)
    {
        OwnerPtr<IGalleryDefinition> opGalleryDef = IGalleryDefinition::Create(L"gmDrawGallery", GBMP_TR(L"绘制方式"));
        for (size_t i = 0; i < cmdStrings.size(); ++i)
        {
            opGalleryDef->AddItem(cmdStrings[i], names[i], names[i], icons[i], cmdStrings[i]);
        }
        opGalleryDef->SetCurrentGalleryItem(pAction->GetCommandId());

        return opGalleryDef;
    }
}

void AddGbmpDynamicPannelUtils::SetupModelLineCreationContext(IAction* pAction, const std::wstring& pageName)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(pAction, L"pAction为空",L"GDMPLab",L"2024-03-30");

    std::vector<std::wstring> cmdStrings;
    std::vector<std::wstring> names;
    std::vector<std::wstring> icons;
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE); names.push_back(GBMP_TR(L"直线")); icons.push_back(L":/images/sketchline/直线16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_RECT_MODEL_LINE); names.push_back(GBMP_TR(L"矩形")); icons.push_back(L":/images/sketchline/矩形16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_ARC_3PTS_MODEL_LINE); names.push_back(GBMP_TR(L"圆弧")); icons.push_back(L":/images/sketchline/三点圆弧16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_ARC_CENTER_MODEL_LINE); names.push_back(GBMP_TR(L"圆心-起点-终点弧")); icons.push_back(L":/images/sketchline/圆心起点终点弧16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_ELLIPSE_ARC_MODEL_LINE); names.push_back(GBMP_TR(L"椭圆弧")); icons.push_back(L":/images/sketchline/椭圆16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_CIRCLE_MODEL_LINE); names.push_back(GBMP_TR(L"圆")); icons.push_back(L":/images/sketchline/圆16px.png");

    {
        std::vector<OwnerPtr<IRibbonGroup>> ribbonGroups;
        OwnerPtr<IRibbonGroup> opDrawGroup = IRibbonGroup::Create(L"gmModelLineDynamicGroup", GBMP_TR(L"绘制"));
        {
            OwnerPtr<IGalleryDefinition> opGalleryDef = CreateDrawGalleryDefinition(pAction, cmdStrings, names, icons);
            opDrawGroup->AddGallery(TransferOwnership(opGalleryDef));
        }
        ribbonGroups.push_back(TransferOwnership(opDrawGroup));

        GcmpActionBase* pActionBase = dynamic_cast<GcmpActionBase*>(pAction);
        if (pActionBase)
        {
            pActionBase->AddDynamicGroup(pageName, TransferOwnership(ribbonGroups), GBMP_TR(L"绘制模型线"));
        }
    }
}

void AddGbmpDynamicPannelUtils::SetupModelLineCreationContextWithoutRef(IAction* pAction, const std::wstring& pageName)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(pAction, L"pAction为空",L"GDMPLab",L"2024-03-30");

    std::vector<std::wstring> cmdStrings;
    std::vector<std::wstring> names;
    std::vector<std::wstring> icons;
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE_WITHOUT_REF); names.push_back(GBMP_TR(L"直线")); icons.push_back(L":/images/sketchline/直线16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_RECT_MODEL_LINE_WITHOUT_REF); names.push_back(GBMP_TR(L"矩形")); icons.push_back(L":/images/sketchline/矩形16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_ARC_3PTS_MODEL_LINE_WITHOUT_REF); names.push_back(GBMP_TR(L"圆弧")); icons.push_back(L":/images/sketchline/三点圆弧16px.png");
    cmdStrings.push_back(ID_CMD_GBMP_DRAW_ARC_CENTER_MODEL_LINE_WITHOUT_REF); names.push_back(GBMP_TR(L"圆心-起点-终点弧")); icons.push_back(L":/images/sketchline/圆心起点终点弧16px.png");
    //cmdStrings.push_back(ID_CMD_GBMP_DRAW_ELLIPSE_ARC_MODEL_LINE_WITHOUT_REF); names.push_back(GBMP_TR(L"椭圆弧")); icons.push_back(L":/images/sketchline/椭圆16px.png");
    {
        std::vector<OwnerPtr<IRibbonGroup>> ribbonGroups;
        OwnerPtr<IRibbonGroup> opDrawGroup = IRibbonGroup::Create(L"gmModelLineDynamicGroup", GBMP_TR(L"绘制"));
        {
            OwnerPtr<IGalleryDefinition> opGalleryDef = CreateDrawGalleryDefinition(pAction, cmdStrings, names, icons);
            opDrawGroup->AddGallery(TransferOwnership(opGalleryDef));
        }
        ribbonGroups.push_back(TransferOwnership(opDrawGroup));

        GcmpActionBase* pActionBase = dynamic_cast<GcmpActionBase*>(pAction);
        if (pActionBase)
        {
            pActionBase->AddDynamicGroup(pageName, TransferOwnership(ribbonGroups), GBMP_TR(L"绘制无关联模型线"));
        }
    }
}

void AddGbmpDynamicPannelUtils::SetupReferencePlaneCreationContext(IAction* pAction, const std::wstring& pageName)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(pAction != nullptr, L"无效Action",L"GDMPLab",L"2024-03-30");

    std::vector<std::wstring> cmdStrings;
    std::vector<std::wstring> names;
    std::vector<std::wstring> icons;
    cmdStrings.push_back(ID_COM_DRAW_STRUCTURE_REFERENCEPLANE_BY_LINE); names.push_back(GBMP_TR(L"绘制")); icons.push_back(L":/images/sketchline/直线16px.png");
    cmdStrings.push_back(ID_COM_DRAW_STRUCTURE_REFERENCEPLANE_BY_Pick); names.push_back(GBMP_TR(L"拾取")); icons.push_back(L":/images/sketchline/选择线16px.png");

    {
        std::vector<OwnerPtr<IRibbonGroup>> ribbonGroups;
        OwnerPtr<IRibbonGroup> opDrawGroup = IRibbonGroup::Create(L"gmCreateReferencePlaneDynamicGroup", GBMP_TR(L"参照面"));
        {
            OwnerPtr<IGalleryDefinition> opGalleryDef = CreateDrawGalleryDefinition(pAction, cmdStrings, names, icons);
            opDrawGroup->AddGallery(TransferOwnership(opGalleryDef));
        }
        ribbonGroups.push_back(TransferOwnership(opDrawGroup));
        GcmpActionBase* pActionBase = dynamic_cast<GcmpActionBase*>(pAction);
        if (pActionBase)
        {
            pActionBase->AddDynamicGroup(pageName, TransferOwnership(ribbonGroups));
        }
    }
}

